package top.hidoctor.auscultation.net.p;

import android.content.Context;
import android.text.TextUtils;

import com.tang.base.BaseResponse;
import com.tang.base.NetMapEncryptUtils;
import com.tang.base.PatchRequest;
import com.tang.net.SuccessConsumer;
import com.tang.util.GsonUtil;

import java.io.File;
import java.util.Map;

import io.reactivex.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import top.hidoctor.auscultation.bean.DictionaryBean;
import top.hidoctor.auscultation.net.PresenterWrapper;
import top.hidoctor.auscultation.net.c.AddXyContract;
import top.hidoctor.auscultation.net.c.GatherContract;
import top.hidoctor.auscultation.net.req.AddLabelReq;
import top.hidoctor.auscultation.net.req.DictionaryReq;

public class GatherPresenter extends PresenterWrapper<GatherContract.View> implements GatherContract.Presenter {


    public GatherPresenter(Context context, GatherContract.View view) {
        super(context, view);
    }

    @Override
    public void getDictionary(final DictionaryReq req) {
        mView.showLoading();
        Map<String, Object> maps = new NetMapEncryptUtils(req).getMaps();
        add(mService.dictionaryList(maps)
                .compose(this.getTransformer())
                .subscribe(new SuccessConsumer<BaseResponse<Object>>(mView, mContext) {
                    @Override
                    public void onSuccess(BaseResponse<Object> response) {
                        mView.hideLoading();
                        String data = GsonUtil.toJsonStr(response.getData());
                        if (!TextUtils.isEmpty(data)) {
                            DictionaryBean bean = GsonUtil.parseJson(data, DictionaryBean.class);
                            mView.getDictionarySuc(bean);
                        }

                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                    }
                }));
    }
}
